<template>
  <!--<keep-alive include="editImg,editNews,editOthers,editProduct">-->
  <a-card
      :bordered="false"
      class="card-area"
      style="height: calc(100% - 55px);overflow: auto;padding-bottom: 53px;">
      <a-form :form="form">
        <a-tabs defaultActiveKey="1" id="tabs">
          <!--商品信息-->
          <a-tab-pane tab="商品信息" key="1">
            <merchandise-news :newsData.sync="dataAll.maaFile" :selectedOption.sync="selectedOptions"></merchandise-news>
          </a-tab-pane>
          <!--图片与视频-->
          <a-tab-pane tab="图片与视频" key="2">
            <img-video :imgData.sync="dataAll.maaFile" :fileListFF.sync="dataAll.fileListF" :fileListMM.sync="dataAll.fileListM" :fileListVVideo.sync="dataAll.fileListVideo"></img-video>
          </a-tab-pane>
          <!--其他信息-->
          <a-tab-pane tab="其他信息" key="3">
            <others-news :othersData.sync="dataAll.maaFile"></others-news>
          </a-tab-pane>
          <!--子产品信息-->
          <a-tab-pane tab="子产品信息" key="5">
            <child-product :productData.sync="dataAll.dataSourceMabChild"></child-product>
          </a-tab-pane>
        </a-tabs>
      </a-form>
      <div class="drawer-bootom-button">
        <div style="width: 50%">
          <a-button @click="handleSubmit" type="primary" :loading="loading">提交</a-button>
          <a-button @click="onClose" type="primary" :loading="loading">取消</a-button>
        </div>
      </div>
    </a-card>
  <!--</keep-alive>-->
</template>
<script>
import db from 'utils/localstorage'
import GlobalVariable from '../../common/global_variable'
import Maa from './Maa'
// 组件
import MerchandiseNews from './components/editNews'
import ImgVideo from './components/editImg'
import OthersNews from './components/editOthers'
import ChildProduct from './components/editProduct'

let user = db.get('USER')
let username = user.username
export default {
  components: {
    MerchandiseNews,
    ImgVideo,
    OthersNews,
    ChildProduct,
    Maa
  },
  name: 'MaaEdits',
  data () {
    return {
      dataAll: {},
      selectedOptions: [],
      actionUrl: GlobalVariable.preRequest + 'file/uploadQCloud',
      selectedRowKeys: [],
      loading: false,
      form: this.$form.createForm(this),
      dataSourceMab: [],
      queryParamsMab: {},
      paginationMab: {
        defaultPageSize: 10000000,
        hideOnSinglePage: true,
        indentSize: 100
      },
      loadingMab: false,
      queryParamsMabChild: {},
      loadingMabChild: false
    }
  },
  beforeRouteEnter (to, from, next) {
    next(vm => vm.showMaa())
  },
  beforeRouteUpdate (to, from, next) {
    this.showMaa()
    next()
  },
  methods: {
    showMaa () {
      this.$api.goods.getMaaBeforeUpdate(this.$route.query.id).then((r) => {
        console.log(r)
        let data = r.data.data
        this.dataAll = data
        this.loading = false
      })
    },
    reset () {
      this.expandedKeys = this.checkedKeys = []
      this.selectedOptions = []
      this.dataAll.fileListF.splice(this.dataAll.fileListF.indexOf(0), 1)
      this.dataAll.fileListM.splice(this.dataAll.fileListM.indexOf(0), 1)
      this.dataAll.fileListVideo.splice(this.dataAll.fileListVideo.indexOf(0), 1)
      let obj = this.dataAll.maaFile
      this.maa01 = obj.maa01
      for (let j in obj) {
        obj[j] = ''
      }
      obj.maa01 = this.maa01
      return obj
      this.form.resetFields()
      this.loading = false
    },
    onClose () {
      this.reset()
      this.$emit('close')
      // this.$router.push({path: `/goods/maa/Maa`})
    },
    handleSubmit () {
      this.form.validateFields((err, values) => {
        if (this.dataAll.maaFile.maa17 === '') {
          this.$message.error('请上传产品主图')
          return false
        }
        if (!err) {
          this.loading = true
          console.log(this.dataAll)
          // 提交商品信息
          this.$api.goods.putMaa(this.dataAll.maaFile).then((r) => {
            console.log(r)
            // return false
            this.reset()
            this.$emit('success')
            this.$message.success('修改商品成功')
            this.$router.push({path: `/goods/maa/maa`})
          }).catch(() => {
            this.loading = false
          })
        }
      })
    }
  }
}
</script>
